/*
 * @Author: zhang ke
 * @Date: 2025-06-20 15:36:46
 * @LastEditors: your name
 * @LastEditTime: 2025-06-28 15:48:37
 * @Description: 
 * @FilePath: \vue3-admin\vite.config.ts
 */
import { defineConfig, loadEnv, type ConfigEnv, type UserConfigExport } from 'vite'
import vue from '@vitejs/plugin-vue'
import  path from  'path' 
import { createSvgIconsPlugin } from  'vite-plugin-svg-icons'
import { viteMockServe } from 'vite-plugin-mock';
// https://vite.dev/config/
export default defineConfig(({command,mode }:ConfigEnv)=>{
  const env = loadEnv(mode,process.cwd())
  return{
        plugins: [
    vue(),
    // 配置svg
    createSvgIconsPlugin({
      iconDirs: [path.resolve(process.cwd(), 'src/assets/icons/svg')],
      symbolId: 'icon-[dir]-[name]',
    }),
    // 配置mock
    viteMockServe({
      mockPath: 'mock', // mock 文件夹的路径
      localEnabled: command == 'serve', // 开启本地 mock
    } as any),

  ],
  //配置scss
  css:{
      preprocessorOptions: {
        scss: {
          javascriptEnabled: true,
          additionalData: `@use "@/styles/variable.scss";`,
        },
      },
    },
   resolve: {
    alias: {
      '@': path.resolve(__dirname, './src') // 配置 @ 指向 src 目录
      },
    },
    // 代理跨域
    server:{
      proxy:{
        [env.VITE_APP_BASE_API]:{
          //本地mock的接口
          target:env.VITE_MOCK_SERVE,
          // target:env.VITE_SERVE,
          changeOrigin:true,
          rewrite: (path) => path.replace(/^\/api/, ''),
        }
      }
    }
  }

})
